package com.example.demo.service.impl;

import com.example.demo.entity.Safetyinspectioncoalmineattributes;
import com.example.demo.entity.Safetyinspectionmonitoringsystem;
import com.example.demo.entity.VO.WellSpaceVO;
import com.example.demo.handle.CoalMineAttributesListParseHandler;
import com.example.demo.handle.MonitoringSystemListParseHandler;
import com.example.demo.handle.SpatialCoordinatesListParseHandler;
import com.example.demo.mapper.SafetyinspectionmonitoringsystemMapper;
import com.example.demo.service.SafetyinspectionmonitoringsystemService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.xml.sax.SAXException;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import java.io.IOException;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author hys
 * @since 2021-07-15
 */
@Service
public class SafetyinspectionmonitoringsystemServiceImpl extends ServiceImpl<SafetyinspectionmonitoringsystemMapper, Safetyinspectionmonitoringsystem> implements SafetyinspectionmonitoringsystemService {

    @Autowired
    private SafetyinspectionmonitoringsystemMapper safetyinspectionmonitoringsystemMapper;

    @Override
    public Integer insertCoalMineAttributesData(String safetyMonitoringXml) {
        //1.获取一个SAXParserFactory的实例对象
        SAXParserFactory factory = SAXParserFactory.newInstance();
        //2.通过factory的newSAXParser()方法获取一个SAXParser类的对象。
        try {
            SAXParser parser = null;
            try {
                parser = factory.newSAXParser();
            } catch (ParserConfigurationException e) {
                e.printStackTrace();
            } catch (SAXException e) {
                e.printStackTrace();
            }
            //创建SAXParserHandler对象
            MonitoringSystemListParseHandler monitoringSystemListParseHandler = new MonitoringSystemListParseHandler();
            try {
                //读取井口信息文件
                parser.parse(safetyMonitoringXml, monitoringSystemListParseHandler);

            } catch (IOException e) {
                e.printStackTrace();
            }
            System.out.println("~~~~~共有" + monitoringSystemListParseHandler.getSafetyinspectionmonitoringsystemArrayList().size() + "个信息");
            // 根据minecode去查找数据库
            for (Safetyinspectionmonitoringsystem safetyinspectionmonitoringsystem : monitoringSystemListParseHandler.getSafetyinspectionmonitoringsystemArrayList()) {
                System.out.println(safetyinspectionmonitoringsystem.getCsMineCode());
                System.out.println(safetyinspectionmonitoringsystem.getCsDataTime());
                System.out.println(safetyinspectionmonitoringsystem.getSsSystemModel());
                System.out.println(safetyinspectionmonitoringsystem.getSsSystemName());
                System.out.println(safetyinspectionmonitoringsystem.getSsSystemMaker());
                System.out.println(safetyinspectionmonitoringsystem.getSsSystemProdate());
                System.out.println(safetyinspectionmonitoringsystem.getSsSystemManum());
                System.out.println(safetyinspectionmonitoringsystem.getSsSystemMaeffec());
                System.out.println(safetyinspectionmonitoringsystem.getSsSystemInstime());
                System.out.println("----------------------------安全监控信息finish---------------------------------");

                safetyinspectionmonitoringsystemMapper.insertSafetyMonitoringData(safetyinspectionmonitoringsystem.getCsMineCode(),safetyinspectionmonitoringsystem.getCsDataTime(),safetyinspectionmonitoringsystem.getSsSystemModel(),safetyinspectionmonitoringsystem.getSsSystemName(),safetyinspectionmonitoringsystem.getSsSystemMaker(),safetyinspectionmonitoringsystem.getSsSystemProdate(),safetyinspectionmonitoringsystem.getSsSystemManum(),safetyinspectionmonitoringsystem.getSsSystemMaeffec(),safetyinspectionmonitoringsystem.getSsSystemInstime());
            }


        } catch (SAXException e) {
            e.printStackTrace();
        }
        return 1;
    }
}
